<?php

inc_class("xml");


$xml_header = '<?xml version="1.0" encoding="Windows-1251"?>';

$main_widget =
'<html>
<head>
<style>
<!--
body, table {
    font-size: 30px;
}
-->
</style>
</head>
<body>
<b:group xmlns:b="http://kadm.org.ua/B" compose="vertical" width="100%" height="100%">
    <b:widget name="header" contains="header.html" width="100%" height="100pt" />
    <b:group compose="horizontal" width="100%" height="auto">
        <b:widget name="content" contains="header.html" width="auto" height="auto" />
        <b:widget name="sidebar" contains="header.html" width="200pt" height="auto" />
    </b:group>
    <b:widget name="footer" contains="footer.html" width="auto" height="50pt" />
</b:group>
</body>
</html>';

$template = new DOMDocument();
$template->loadXML($xml_header.$main_widget);

$xsl = new DOMDocument();
$xsl->load(SITE_ROOT.'widget2xhtml.xsl');

$x = new xml();
$x = $x->Transform($template, $xsl);
//Header('Content-Type: text/xml');
//die( $x->saveXML());


class stream
{

    protected $_M_string;
    protected $_M_is_not_end;
    protected $_M_position;
    protected $_M_length;

    function __construct($string)
    {
        $this->_M_position   = 0;
        $this->_M_string     = $string;
        $this->_M_length     = strlen($this->_M_string);
        $this->_M_is_not_end = $this->_M_length ? true : false;
    }

    function Position()
    {
        return $this->_M_position + 1;
    }

    function NextCh()
    {
        if ($this->_M_position < ($this->_M_length - 1)) {
            $this->_M_position++;
        } else {
            $this->_M_is_not_end = false;
        }
    }

    function Skip($n)
    {
        if ($this->_M_position < ($this->_M_length - 1 - $n)) {
            $this->_M_position += $n;
        } else {
            $this->_M_is_not_end = false;
        }
    }

    function Ch()
    {
        return $this->_M_string[$this->_M_position];
    }

    function NotEnd()
    {
        return $this->_M_is_not_end;
    }
}

class tree
{
    protected $DOM;
    protected $currNode;

    function __construct()
    {
        $this->DOM =& new DOMDocument();
        $this->setCurrNode($this->DOM);
    }

    function appendChild($name)
    {
        $child =& $this->DOM->createElement($name);
        return $this->getCurrNode()->appendChild($child);
    }

    function createChild($name)
    {
        return $this->setCurrNode($this->appendChild($name));
    }

    function write($text)
    {
        $child =& $this->DOM->createTextNode($text);
        $this->getCurrNode()->appendChild($child);
    }

    function endChild()
    {
        if ($this->getCurrNode()->parentNode) {
            $this->setCurrNode($this->getCurrNode()->parentNode);
        } else {
            // End of document
        }
    }

    function getDOM()
    {
        return $this->DOM;
    }

    function &setCurrNode(DOMNode &$node)
    {
        return $this->currNode =& $node;
    }

    function &getCurrNode()
    {
        return $this->currNode;
    }

}

class scanner extends stream
{

    protected $tree;

    function __construct($string)
    {
        parent::__construct($string);
        $this->tree = new tree();
    }

    function Lexeme()
    {
        return $this->getCurrNode();
    }

    function NotComplate()
    {
        return $this->getCurrNode();
    }

    function NextLexeme()
    {

    }

    protected function createChild($name)
    {
        return $this->tree->createChild($name);
    }

    protected function write($text)
    {
        return $this->tree->write($text);
    }

    protected function endChild()
    {
        return $this->tree->endChild();
    }

}

class css_scanner extends scanner
{

    private $state;

    protected function process()
    {
        $this->state = 0;
        $this->createChild('root');












        $this->endChild();
    }


}

$scaner = new css_scanner("

td {
    font-size: 10pt;
}

");

/*$tree = $scaner->parse();

Header('Content-Type: text/xml');
die($tree->saveXML());
             */

?>